package cn.tedu.charging.cost.dao.repository.impl;

import cn.tedu.charging.cost.dao.Mapper.CostRuleMapper;
import cn.tedu.charging.cost.dao.repository.CostRuleRepository;
import cn.tedu.charging.cost.pojo.po.CostRulePO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class CostRuleRepositoryImpl implements CostRuleRepository {
    @Autowired
    private CostRuleMapper costRuleMapper;
    @Override
    //查询规则列表
    public List<CostRulePO> getCostRulesByStationId(Integer stationId) {
        QueryWrapper<CostRulePO> queryWrapper = new QueryWrapper<>();
        //CollectionUtils Spring 提供的集合相关的工具类
        //Collections java 提供的集合相关的工具类
        queryWrapper.eq("station_id",stationId);
        return  costRuleMapper.selectList(queryWrapper);

    }

    @Override
    public CostRulePO getMatchCostRule(Integer stationId, Integer gunType, Integer hour) {
        QueryWrapper<CostRulePO> queryWrapper = new QueryWrapper<>();
        //queryWrapper.lt（）——小于
        //queryWrapper.le（）——小于等于
        //queryWrapper.gt（）——大于
        //queryWrapper.ge（）——大于等于
        //queryWrapper.eq（）——等于
        //queryWrapper.ne（）——不等于
        queryWrapper.eq("station_id", stationId);
        queryWrapper.eq("gun_type", gunType);
        queryWrapper.ge("start_time", hour);
        queryWrapper.lt("end_time", hour);
        return costRuleMapper.selectOne(queryWrapper);
    }
}
